home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / faq-s.zip / TIMEBANK.PAS < prev    next >
Pascal/Delphi Source File  |  1990-08-29  |  5KB  |  207 lines

  1. program skeleton;
  2.  
  3. {
  4.  
  5.                FAQ Door Skeleton
  6.  
  7. }
  8.  
  9.  
  10.  
  11. uses
  12.   Gentypes, { All type and constant declarations }
  13.   Configrt, { Configuration declarations / procedures }
  14.   Modem,    { Modem support }
  15.   Statret,  { System status declarations / procedures }
  16.   Gensubs,  { General subroutines: lowest level }
  17.   Subs1,    { First subroutine library }
  18.   Windows,  { Routines to manage the split screen }
  19.   Subs2,    { Second subroutine library: higher level I/O }
  20.   UserRet,  { Does User Work for us }
  21.   init;
  22.  
  23.  
  24. type bankrec = record
  25.     balance:integer;
  26.     lastt:char;
  27.     lasta:integer;
  28.     lastw:longint;
  29.     end;
  30.  
  31. var    bnkfile:file of bankrec; acct:bankrec;
  32.  
  33.  
  34. procedure returnfromdoor;
  35. var t:sstr;
  36. begin
  37.   readdataarea;
  38.   baudrate:=valu(paramstr(2));
  39.   online:=baudrate<>0;
  40.   local:=not online;
  41.   if baudrate=0 then baudrate:=defbaudrate;
  42.   setparam (usecom,baudrate,parity);
  43.   if unum=valu(paramstr(1)) then readurec else begin
  44.     unum:=valu(paramstr(1));
  45.     readurec;
  46.     if (unum<1) or (unum>numusers) then begin
  47.       unum:=-1;
  48.       exit
  49.     end;
  50.     logontime:=timer;
  51.     logofftime:=timer+urec.timetoday
  52.   end;
  53.   if hungupon then begin
  54.     unum:=-1;
  55.     exit
  56.   end;
  57.   fromdoor:=true;
  58.   settimeleft (urec.timetoday);
  59.   t:=paramstr(4);
  60.   if t=''
  61.     then returnto:='D'
  62.     else returnto:=upcase(t[1])
  63. end;
  64.  
  65. procedure setuplocal;
  66. var i:integer;
  67. begin
  68.     assign(bnkfile,'TIMEBANK.ACC');
  69.     if not exist('timebank.acc') then begin
  70.                     rewrite(bnkfile);
  71.                     acct.balance:=0;
  72.                     acct.lastw:=0;
  73.                     acct.lastt:=' ';
  74.                     acct.lasta:=0;
  75.                     for i:=1 to 1200 do write(bnkfile,acct);
  76.                     end;
  77.     reset(bnkfile); seek(bnkfile,unum-1);
  78.     read(bnkfile,acct);
  79. end;
  80.  
  81. procedure quickrag;
  82. begin
  83.     writeln; writeln('Don''t be a fool, ',unam);
  84. end;
  85.  
  86. procedure writebank;
  87. begin
  88.     seek(bnkfile,unum-1); write(bnkfile,acct);
  89. end;
  90.  
  91. procedure showbalance;
  92. begin
  93.     writehdr('Account #'+strr(unum)+' - '+unam); writeln;
  94.     writeln('Current balance : '^S,acct.balance,^R' minutes.');
  95.       write('Last Transaction: '^S);
  96.       case acct.lastt of
  97.         'W'    : write('Withdrawal');
  98.         'D'    : write('Deposit');
  99.         else begin
  100.             writeln('None');
  101.             writeln;
  102.             exit;
  103.             end;
  104.         end;
  105. writeln(^R' of '^P,acct.lasta,^R' minutes on '^P,datestr(acct.lastw),^R);
  106.     writeln;
  107. end;
  108.  
  109. procedure deposit;
  110. var amt:integer;
  111. begin
  112.     writeln;
  113.     if urec.timetoday <= 5 then begin
  114.         writeln('You have only ',urec.timetoday,' now!');
  115.         exit;
  116.         end;
  117.  
  118.     if acct.balance = 60 then begin
  119.     writeln('The FTDC only insures you up to 60 minutes!');
  120.                 exit;
  121.                 end;
  122.     showbalance;
  123.     writestr('Deposit how many minutes? &');
  124.     amt:=valu(input); writeln;
  125.     if amt <= 0 then exit;
  126.     if amt > urec.timetoday then begin
  127.             quickrag;
  128.             writeln('You haven''t got that much left!');
  129.             exit;
  130.             end;
  131.     if amt+acct.balance > 60 then begin
  132. writeln('The FTDC will only insure up to 60 minutes, would you settle for');
  133.  write ('depositing only '+strr(60-acct.balance)+' minutes instead? ');
  134.  writestr('&');
  135.  
  136.       if upcase(input[1])<>'Y' then exit;
  137.       amt:=60-acct.balance;
  138.       end;
  139.     acct.lasta:=amt;
  140.     acct.lastw:=now;
  141.     acct.lastt:='D';
  142.     acct.balance:=acct.balance+amt;
  143.     urec.timetoday:=urec.timetoday-amt;
  144.     writebank;
  145.     writeln(^S,amt,^R' minutes added to your account.');
  146. end;
  147.  
  148. procedure withdraw;
  149. var amt:integer;
  150. begin
  151.     writeln;
  152.     if acct.balance <= 0 then acct.balance:=0;
  153.     if acct.balance = 0 then begin
  154.     quickrag;
  155.     writeln('You have nothing to withdraw!');
  156.                 exit;
  157.                 end;
  158.     showbalance;
  159.     writestr('Withdraw how many minutes? &');
  160.     amt:=valu(input); writeln;
  161.     if amt <= 0 then exit;
  162.     if amt > acct.balance then begin
  163.         writeln('You haven''t got that much in your account.');
  164.             exit;
  165.             end;
  166.  
  167.     acct.lasta:=amt;
  168.     acct.lastw:=now;
  169.     acct.lastt:='W';
  170.     acct.balance:=acct.balance-amt;
  171.     urec.timetoday:=urec.timetoday+amt;
  172.     writebank;
  173.     writeln(^S,amt,^R' minutes added to today''s time.');
  174. end;
  175.  
  176.  
  177.  
  178. var q:char;
  179.  
  180. begin
  181.   readconfig;
  182.   validconfiguration;
  183.   initboard(true);
  184.   returnfromdoor;
  185.   setuplocal;
  186.  
  187.   repeat
  188.         writeln (^P'['^S'Q'^P'] '^R'Quit');
  189.         writeln (^P'['^S'W'^P'] '^R'Withdraw Time');
  190.         writeln (^P'['^S'D'^P'] '^R'Deposit Time');
  191.         writeln (^P'['^S'B'^P'] '^R'Show Balance'^M);
  192.     writestr('[Time Bank Menu]: ');
  193.         q:=upcase(input[1]);
  194.     case q of
  195.         'Q': begin
  196.                 writeln;
  197.             writeln('One moment, '^P+unam+^R', returning to FAQ.');
  198.             writeln; ensureclosed;
  199.             halt(0);
  200.               end;
  201.         'W': withdraw;
  202.         'D': deposit;
  203.         'B': showbalance;
  204.         end
  205.       until hungupon
  206. end.
  207.